package nc.hw;

public class HJ32 {

    private static int maxOfCicle(String str, int indexX, int indexY) {
        int i = indexX;
        int j = indexY;
        int max = 0;
        while (i >= 0 && j < str.length() && str.charAt(i) == str.charAt(j)) {
            max = Integer.max(j - i + 1, max);
            i -= 1;
            j += 1;
        }
        return max;
    }

    private static int max(String str) {
        int max = 0;
        for (int i = 0; i < str.length(); i++) {
            max = Integer.max(maxOfCicle(str, i, i), max);
            max = Integer.max(maxOfCicle(str, i, i + 1), max);
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(max("ABBA"));
        System.out.println(max("ABBBA"));
        System.out.println(max("12HHHHA"));
    }

}
